package engine.newUi
{
	import flash.display.MovieClip;
	import flash.display.Stage;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import newx.StageInfo;
	import newx.com.ResManager;
	import newx.com.config.StaticIni;
	import newx.com.control.button.NxButton;
	import newx.com.control.text.NxLabel;
	import newx.com.control.window.NxWindow;
	import newx.com.control.window.NxWindowDragType;
	import newx.com.control.window.NxWindowEvent;

	/**
	 * 
	 * @author zhouqiang
	 * 
	 */	
	public class AlertNextUI extends NxWindow
	{
		public	static const 	YES			:int	=	0x1000;
		public	static const 	NO			:int	=	0x0100;
		public	static const 	OK			:int	=	0x0010;
		public	static const 	CANCEL		:int	=	0x0001;
		
		//private var _self:AlertNextUI;
		/**提示框标题*/
		private var _title:String;
		
		/**提示框内容*/
		private var _text:String;
		
		private var textLab:NxLabel 	=	new NxLabel();
			
		private var choseBtn:MovieClip	=	new MovieClip();
		
		/**OK按钮*/
		private var OKbtn:NxButton		=	new NxButton();
		
		/**回调函数*/
		private var _backFun:Object;
		
		/**是否选择*/
		private var _isChose:Boolean	=	true;
		
		/**传递数据*/
		private var pList:Array			=	[];
		
		/**提示框标示集合*/
		public static var signObj:Object		=	new Object();
		
		/**提示框标志*/
		private static var signStr:Object		=	new Object();
		
		//
		private var noPromptText:TextField		=	new TextField();
		//private static const 
		public function AlertNextUI(title:String,text:String,Fun:Object,isShow:Boolean,arr:Array = null)
		{
			//super();
			_title	=	title;
			_text	=	text;
			this.titleSize		=	300;
			this.width			=	300;
			this.height			=	150;
			this.closeBtnVisible=	true;
			this.title			=	title;
			this.dragSpaceType	=	NxWindowDragType.Window_ALL;
			_backFun			=	Fun;
			pList				=	arr;
			setText();
			setBtn();
			setOKbtn();
			this.addEventListener(NxWindowEvent.WINDOW_CLOSE,OnCloseHanlde);
		}

		/**
		 * 
		 * @param title 标题
		 * @param text  提示类容
		 * @param Fun	回调函数，fun（isShow,arr）
		 * @param isShow是否再次打开次提示框
		 * @param str	这个提示框的唯一标示符，建议以所在类的名字+数字来命名
		 * @param arr=null	传递的数据
		 * 
		 */		
		public static function getInstance(title:String,text:String,Fun:Object,isShow:Boolean,str:String,arr:Array = null):void
		{
			var _self:AlertNextUI;
			signStr		=	str;
			if(!signObj.hasOwnProperty(str))
			{
				signObj[str]		=	true;
				//每个提示框只能显示一个
				signObj["type"]		=	true;
				_self	=	new AlertNextUI(title,text,Fun,isShow,arr);
				_self.x				=	200;
				_self.y				=	200;
				StageInfo.stage.addChild(_self);
			}
			else
			{
				if(signObj[str]	 && !signObj["type"])
				{
					_self			=	new AlertNextUI(title,text,Fun,isShow,arr);
					_self.x			=	200;
					_self.y			=	200;
					StageInfo.stage.addChild(_self);
				}
			}
					
		}
		
		/**
		 *设置文本 
		 * 
		 */		
		private function setText():void
		{
			textLab.x			=	50;
			textLab.y			=	40;
			textLab.htmlText	=	_text;
			this.addChild(textLab);
		}
		
		/**
		 * 设置按钮
		 * 选择是否不再打开此界面
		 */		
		private function setBtn():void
		{	
			choseBtn			=	ResManager.newResClass("custSkin_13") as MovieClip;
			choseBtn.x			=	230;
			choseBtn.y			=	95;
			choseBtn.gotoAndStop(1);
			choseBtn.data		=	1;
			choseBtn.buttonMode	=	true;
			this.addChild(choseBtn);
			choseBtn.addEventListener(MouseEvent.CLICK,onSurechoseHandle);
		}
		
		private function onSurechoseHandle(e:MouseEvent):void
		{
			var mc:MovieClip	=	e.target as MovieClip;
			mc.data				=	(mc.data == 1)?2:1;
			signObj[signStr]	=	(mc.data == 2)?false:true; 
			mc.gotoAndStop(mc.data);
		}
		
		/**
		 * 确认按钮
		 * 
		 */	
		private function setOKbtn():void
		{
			OKbtn.x		=	50;
			OKbtn.y		=	90;
			OKbtn.skin	=	"Button_1";
			OKbtn.label	=	StaticIni.getSwfLangStr("AlertEx_16");
			this.addChild(OKbtn);		
			OKbtn.addEventListener(MouseEvent.CLICK,OnisClickOkHandle);
		}
		
		private function OnisClickOkHandle(e:MouseEvent):void
		{
			_backFun.call(this,signObj[signStr],pList);
			delete signObj[signStr];
			this.hide();
		}
			
		/**
		 * 关闭界面
		 */
		private function OnCloseHanlde(e:NxWindowEvent):void
		{
			delete signObj[signStr];
			signObj["type"]			=	false;
			signObj[signStr]		=	true;
			this.hide();
		}
	}
}